package java12;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.Random;
import java.util.Scanner;

public class RandomInput1 {

	public static void main(String[] args) throws FileNotFoundException {
		String FileName = "d:/test.txt";
		int count = 1000 * 10000;
//		 PW
		 PrintWriter pw = null;
		 try {
		 pw = new PrintWriter(FileName);
		 for (int i = 0; i < count; i++) {
		 pw.println(new Random().nextInt(100000));
		 }
		 } catch (FileNotFoundException e) {
		 e.printStackTrace();
		 } finally {
		 pw.close();
		 }

		// Using BufferedReader
		BufferedReader br = null;
		try {
			br = new BufferedReader(new FileReader(new File(FileName)));
			while (br.readLine() != null) {
			}
			;

		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				br.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		// using Scanner
		Scanner scanner = null;
		try {
			scanner = new Scanner(new File(FileName));
			while (scanner.hasNextLine()) {
				scanner.nextLine();
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} finally {
			scanner.close();
		}
	}
}
